<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;

/**
 * Common controller
 * 公共方法
 */
class CommonController extends Controller
{

    public function actionsGetMobileLoc($date){

        header("Content-type:text/html;charset=utf-8");

        $url = "http://yii2cms.cn/backend/web/index.php?r=text/apply";

        $result = $this->curl_https($url);

        $result = (array)json_decode($result);

        if (!empty($result['data'])) {
            $result = (array)$result['data'][0];
            $data['city'] = empty($result['city']) ? '' : $result['city'];
            $data['province'] = empty($result['prov']) ? $result['city'] : $result['prov'];
            $data['type'] = empty($result['type']) ? '未知' : $result['type'];
        }

        return $data;

    }
    private function curl_https($url){

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

        curl_setopt($ch, CURLOPT_HEADER, FALSE);

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_REFERER, $url);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

        $result = curl_exec($ch);

        curl_close($ch);

        //-------请求为空
        if(empty($result)){

            return false;

        }

        return $result;


    }


}
